package sourceagile.webservices.local;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.jettison.json.JSONObject;

import sourceagile.server.localFileRepository.GetLocalClassFile;
import sourceagile.webservices.GetCallback;

@SuppressWarnings("serial")
public class GetLocalClassFileServlet extends HttpServlet {

	// http://localhost:8080/LiveSourceWebServices/GetLocalFileContentService
	// ?projectID=flaretag
	// &filePath=index.php
	// &username=null&password=null

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws IOException {

		String projectID = request.getParameter("projectID");

		String filePath = request.getParameter("filePath");

		String username = request.getParameter("username");

		String password = request.getParameter("password");

		JSONObject fileContent = GetLocalClassFile.jsonClassDocument(projectID,
				filePath);

		String answer = GetCallback.getCallback(
				request.getParameter("callback"), fileContent.toString());

		response.setContentType("text/javascript");

		response.getWriter().println(answer);
	}
}
